Page({
  data: {
    aaa:1,
    scheduleList: [{
        weekNum: 1,
        weekShow:"星期一",
        today: false,
        year: "",
        month: "",
        day: "",
        firstSchedule:{
          content: "",
          type: ""
        }
      },
      {
        weekNum: 2,
        weekShow:"星期二", 
        today: false,
        year: "",
        month: "",
        day: "",
        firstSchedule:{
          content: "",
          type: ""
        }
      },
      {
        weekNum: 3,
        weekShow:"星期三",
        today: false,
        year: "",
        month: "",
        day: "",
        firstSchedule:{
          content: "",
          type: ""
        }
      },
      {
        weekNum: 4,
        weekShow:"星期四",
        today: false,
        year: "",
        month: "",
        day: "",
        firstSchedule:{
          content: "",
          type: ""
        }
      },
      {
        weekNum: 5,
        weekShow:"星期五",
        today: false,
        year: "",
        month: "",
        day: "",
        firstSchedule:{
          content: "",
          type: ""
        }
      },
      {
        weekNum: 6,
        weekShow:"星期六",
        today: false,
        year: "",
        month: "",
        day: "",
        firstSchedule:{
          content: "",
          type: ""
        }
      },
      {
        weekNum: 7,
        weekShow:"星期日",
        today: false,
        year: "",
        month: "",
        day: "",
        firstSchedule:{
          content: "",
          type: ""
        }
      }]
  },
  onLoad: function(options){
    var oneDay = 24 * 60 * 60 * 1000;
    var today = Date.parse(new Date());
    var delta = new Date().getDay() - 1;
    delta = delta == -1 ? 6 : delta;
    var scheduleItemToday = "scheduleList[" + delta + "].today"
    this.setData({
      [scheduleItemToday]: true
    });
    for(var i = 0; i <= 6; i++){
      var scheduleItemDay = "scheduleList[" + i + "].day";
      var scheduleItemMonth = "scheduleList[" + i + "].month";
      var scheduleItemYear = "scheduleList[" + i + "].year";
      var res = new Date(today + (i-delta) * oneDay);
      this.setData({
        [scheduleItemDay]: res.getDate(),
        [scheduleItemMonth]: res.getMonth()+1,
        [scheduleItemYear]: res.getFullYear()
      });
    }
    var app = getApp()
    for(var i = 0; i <= 6; i++){
      var lastSche = {empty:true}
      var minTime = new Date("2001-01-01 00:00:00")
      for(var j = 0; j <= app.userSchedules[i].length-1; j++){
        var sche = app.userSchedules[i][j]
        var time = new Date("2000-01-01 "+sche.startTime+":00")
        if(time < minTime){
          minTime = sche.startTime
          lastSche = sche
        }
      }
      this.setData({
        ["scheduleList[" + i + "].firstSchedule.content"]: lastSche.content,
        ["scheduleList[" + i + "].firstSchedule.type"]: lastSche.type
      })
    }
  },
  onShow: function() { //此处需要改进！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！！
    var app = getApp()
    for(var i = 0; i <= 6; i++){
      var lastSche = {empty:true}
      var minTime = new Date("2001-01-01 00:00:00")
      for(var j = 0; j <= app.userSchedules[i].length-1; j++){
        var sche = app.userSchedules[i][j]
        var time = new Date("2000-01-01 "+sche.startTime+":00")
        if(time < minTime){
          minTime = sche.startTime
          lastSche = sche
        }
      }
      this.setData({
        ["scheduleList[" + i + "].firstSchedule.content"]: lastSche.content,
        ["scheduleList[" + i + "].firstSchedule.type"]: lastSche.type
      })
    }
  },
  toDetails: function(event){
    var detailDate = this.data.scheduleList[event.currentTarget.id];
    wx.navigateTo({
      url: "../details/details?y=" + detailDate.year + "&m=" + detailDate.month + "&d=" + detailDate.day + "&w=" + detailDate.weekShow
    })
  }
})